package com.boot4g.admin.module.publish.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.boot4g.admin.module.publish.service.SysDicService;
import com.boot4g.entity.SysDicEntity;
import com.boot4g.utils.PageUtils;
import com.boot4g.utils.Query;
import com.boot4g.utils.R;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 
 * 
 * @author chenjinjie
 * @email guangyaoliangzijie@163.com
 * @date 2018-08-17 10:44:25
 */
@RestController
@RequestMapping("sys/dic")
public class SysDicController {
	@Autowired
	private SysDicService sysDicService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	//@RequiresPermissions("SysDic:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

        Page<SysDicEntity> page = sysDicService.selectByPage(query.getPagination(),query);

        PageUtils pageUtil = new PageUtils(page.getRecords(), page.getTotal(), query.getLimit(), query.getCurrPage());

		return R.ok().put("page", pageUtil);
	}

	/**
	 * 查询
	 */
	@RequestMapping("/select")
	public R select(@RequestParam("code") String code){
		Map<String, Object> params = new HashedMap();
		params.put("code", code);
		List<SysDicEntity> SysDicList = sysDicService.selectByMap(params);

		return R.ok().put("list", SysDicList);
	}
	/**
	 * 信息
	 */
	@RequestMapping("/info/{rid}")
	//@RequiresPermissions("SysDic:info")
	public R info(@PathVariable("rid") Long rid){
		SysDicEntity SysDic = sysDicService.selectById(rid);
		
		return R.ok().put("SysDic", SysDic);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	//@RequiresPermissions("SysDic:save")
	public R save(@RequestBody SysDicEntity SysDic){
		sysDicService.insert(SysDic);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	//@RequiresPermissions("SysDic:update")
	public R update(@RequestBody SysDicEntity SysDic){
		sysDicService.updateById(SysDic);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	//@RequiresPermissions("SysDic:delete")
	public R delete(@RequestBody Long[] rids){
		sysDicService.deleteBatchIds(Arrays.asList(rids));
		
		return R.ok();
	}
	
}
